package ldh.im.fxgui.controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import ldh.im.fxbase.util.StageUtil;

public class StageControlController {

    @FXML private Button maxBtn;
    @FXML private Button remaxBtn;
    @FXML private Pane maxPane;

    private Stage newState = null;

    @FXML
    private void close(ActionEvent actionEvent) {
        if(StageUtil.isSupportTray()) {
            getStage().hide();
            getStage().setIconified(true);
        } else {
            getStage().close();
        }
    }

    @FXML private void min(ActionEvent actionEvent) {
        getStage().setIconified(true);
    }

    @FXML private void max(ActionEvent actionEvent) {
        getStage().setMaximized(true);
        maxBtn.setVisible(false);
        remaxBtn.setVisible(true);
    }

    @FXML private void remax(ActionEvent actionEvent) {
        getStage().setMaximized(false);
        maxBtn.setVisible(true);
        remaxBtn.setVisible(false);
    }

    public void hideMax() {
        maxPane.setVisible(false);
        maxPane.setManaged(false);
    }

    public void setStage(Stage stage) {
        this.newState = stage;
    }

    private Stage getStage() {
        if (newState == null) return StageUtil.getStage();
        return newState;
    }
}
